package com.zh.work.controller.platform.agent;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zh.common.entity.JSONResult;
import com.zh.work.dao.record.AgentRecordMapper;
import com.zh.work.entity.agent.ChangeAgentAccount;
import com.zh.work.service.platform.agent.AgentRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * code is far away from bug with the animal protecting
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃代码无BUG！
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 *
 * @Description: 代理商资料变更控制器
 * @Author: Li.HuiNeng
 * @Create in: 2019-11-23 15:33
 * @Version: 1.0.1
 */
@Api(value = "代理商资料变更控制器", produces = "application/json", tags = {"代理商资料变更控制器"})
@RestController
@RequestMapping("/agentAudit")
public class AgentAuditController {

    /**
     * @Description: 业务层级处理时使用
     * ------------------------
     * @Author: Li.HuiNeng
     * @Date: 2019/11/23
     */
    @Autowired
    private AgentRecordService recordService;


    /**
     * @Description: 系统操作级别时使用
     * ------------------------
     * @Author: Li.HuiNeng
     * @Date: 2019/11/23
     */
    @Autowired
    private AgentRecordMapper recordMapper;

    @ApiOperation(value = "查询变更记录", tags = {"getAgentAuditHistory"}, notes = "查询变更记录")
    @GetMapping("getAgentAuditHistory")
    public JSONResult<Object> getAgentAuditHistory(@ApiParam(value = "变更记录实体信息", name = "changeAgentAccount") ChangeAgentAccount changeAgentAccount,
                                                   @ApiParam(value = "起始页", name = "pageNo") Integer pageNo,
                                                   @ApiParam(value = "当前页显示数量", name = "pageNo") Integer pageSize) {
        JSONResult<Object> jsonResult = new JSONResult<>();
        try {
            Page<ChangeAgentAccount> page = new Page<>(pageNo, pageSize);
            IPage<ChangeAgentAccount> result = recordService.getAgentAuditList(page, changeAgentAccount);
            jsonResult.setSuccess(true);
            jsonResult.setTotal(result.getTotal());
            jsonResult.setData(result.getRecords());
        } catch (Exception e) {
            jsonResult.setSuccess(false);
            jsonResult.setMessage(e.getLocalizedMessage());
            e.printStackTrace();
        }
        return jsonResult;
    }

    @ApiOperation(value = "查询变更资料各状态占比", tags = {"getAuditPercent"}, notes = "查询变更资料各状态占比")
    @GetMapping("getAuditPercent")
    public JSONResult<Object> getAuditPercent(@ApiParam(value = "变更记录实体信息", name = "changeAgentAccount") ChangeAgentAccount account) {
        JSONResult<Object> jsonResult = new JSONResult<>();
        try {
            List<Integer> list = this.recordMapper.getAuditPercent(account.getAuditStartTime(),account.getAuditEndTime(),account.getAddStartTime(),account.getAddEndTime());
            if (list.size() == 3)
                jsonResult.setSuccess(true);
            else
                jsonResult.setSuccess(false);
            jsonResult.setData(list);
        } catch (Exception e) {
            jsonResult.setSuccess(false);
            jsonResult.setMessage(e.getLocalizedMessage());
            e.printStackTrace();
        }
        return jsonResult;
    }
}
